package com.fbli.Thread.method;

public class ThreadMethod02 {
    public static void main(String[] args) throws InterruptedException {
        T1 t1 = new T1();
        t1.start();
        for (int i = 0; i < 20; i++) {
            Thread.sleep(1000);
            System.out.println("主线程(小弟) 吃了" + i + " 包子");
            if (i==5){
                System.out.println("主线程(小弟) 让子线程（老大）先吃");
                //t1.join();//相当于让t1线程先执行完毕 插队 一定成功
                //礼让，不一定成功，看cpu资源紧张不紧张
                Thread.yield();//主线程礼让
                System.out.println("线程（老大）吃完了 主线程(小弟)接着吃..");

            }
        }
    }
}
class T1 extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 20; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("子线程 吃了" + i + "包子");
        }
    }
}